package com.ant.cn.base.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class IndexFilter implements Filter{

	@Override
	public void destroy() {
		System.out.println("IndexFilter destory ");
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/";
		String ss=request.getParameter("type");
		String  url=request.getLocalAddr();
		System.out.println("url="+url+",  type="+ss);
		if(ss!=null)
		if(ss.equals("error")){
			request.getRequestDispatcher( "error.jsp").forward(request, response);
			return ;
		}else if(ss.equals("login")){
			request.getRequestDispatcher("login.jsp").forward(request, response);
			return ;
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		System.out.println("indexFilter inited ");
	}

}
